home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1995-03-10 | 12.5 KB | 265 lines | [TEXT/3PRM] |
- implementation module windowDef;
-
-
- //
- // WindowDefinitions:
- //
-
-
- import StdInt;
- import commonDef;
- from ioState import IOState;
- from deltaPicture import Picture, Rectangle, DrawFunction;
-
-
- :: WindowDef *s *io
- = ScrollWindow WindowId WindowPos WindowTitle
- ScrollBarDef ScrollBarDef
- PictureDomain MinimumWindowSize InitialWindowSize
- (UpdateFunction s) [WindowAttribute s io]
- | FixedWindow WindowId WindowPos WindowTitle
- PictureDomain (UpdateFunction s) [WindowAttribute s io];
-
- :: WindowId :== Int;
- :: WindowPos :== (!Int, !Int);
- :: WindowTitle :== String;
- :: ScrollBarDef = ScrollBar ThumbValue ScrollValue;
- :: ThumbValue = Thumb Int;
- :: ScrollValue = Scroll Int;
- :: MinimumWindowSize :== (!Int, !Int);
- :: InitialWindowSize :== (!Int, !Int);
- :: UpdateArea :== [Rectangle];
- :: UpdateFunction *s :== UpdateArea -> (s -> (s,[DrawFunction]));
-
- :: WindowAttribute *s *io
- = Activate (WindowFunction s io)
- | Deactivate (WindowFunction s io)
- | GoAway (WindowFunction s io)
- | Mouse SelectState (MouseFunction s io)
- | Keyboard SelectState (KeyboardFunction s io)
- | Cursor CursorShape
- | StandByWindow;
-
- :: WindowFunction *s *io :== s -> *(io -> (s, io));
- :: MouseFunction *s *io :== MouseState -> (s -> *(io -> (s, io)));
- :: KeyboardFunction *s *io :== KeyboardState-> (s -> *(io -> (s, io)));
-
- :: CursorShape = StandardCursor | BusyCursor | IBeamCursor
- | CrossCursor | FatCrossCursor | ArrowCursor | HiddenCursor;
-
-
- IsScrollWindow :: !(WindowDef s io) -> Bool;
- IsScrollWindow (ScrollWindow id pos t h v pd min init f as) = True;
- IsScrollWindow window = False;
-
- WindowDefGetWindowId :: !(WindowDef s io) -> WindowId;
- WindowDefGetWindowId (ScrollWindow id pos t h v pd min init f as) = id;
- WindowDefGetWindowId (FixedWindow id pos t pd f as) = id;
-
- WindowDefGetPosition :: !(WindowDef s io) -> WindowPos;
- WindowDefGetPosition (ScrollWindow id pos t h v pd min init f as) = pos;
- WindowDefGetPosition (FixedWindow id pos t pd f as) = pos;
-
- WindowDefGetTitle :: !(WindowDef s io) -> String;
- WindowDefGetTitle (ScrollWindow id pos t h v pd min init f as) = t;
- WindowDefGetTitle (FixedWindow id pos t pd f as) = t;
-
- WindowDefGetScrollBarDefs :: !(WindowDef s io) -> (!ScrollBarDef, !ScrollBarDef);
- WindowDefGetScrollBarDefs (ScrollWindow id pos t h v pd min init f as) = (h, v);
-
- WindowDefGetPictureDomain :: !(WindowDef s io) -> PictureDomain;
- WindowDefGetPictureDomain (ScrollWindow id pos t h v pd min init f as) = pd;
- WindowDefGetPictureDomain (FixedWindow id pos t pd f as) = pd;
-
- WindowDefGetMinimumSize :: !(WindowDef s io) -> MinimumWindowSize;
- WindowDefGetMinimumSize (ScrollWindow id pos t h v pd min init f as) = min;
- WindowDefGetMinimumSize (FixedWindow id pos t pd=:((xl,yl), (xr,yr)) f as) = (xr-xl, yr-yl);
-
- WindowDefGetInitialSize :: !(WindowDef s io) -> InitialWindowSize;
- WindowDefGetInitialSize (ScrollWindow id pos t h v pd min init f as) = init;
- WindowDefGetInitialSize (FixedWindow id pos t pd=:((xl,yl), (xr,yr)) f as) = (xr-xl, yr-yl);
-
- WindowDefGetUpdate :: !(WindowDef s io) -> UpdateFunction s;
- WindowDefGetUpdate (ScrollWindow id pos t h v pd min init f as) = f;
- WindowDefGetUpdate (FixedWindow id pos t pd f as) = f;
-
- WindowDefHasAttribute :: !(WindowDef s io) !(WindowAttribute s io) -> Bool;
- WindowDefHasAttribute (ScrollWindow id pos t h v pd min init f as) a
- = WindowAttributesHaveAttribute as a;
- WindowDefHasAttribute (FixedWindow id pos t pd f as) a
- = WindowAttributesHaveAttribute as a;
-
- WindowDefIsStandBy :: !(WindowDef s io) -> Bool;
- WindowDefIsStandBy (ScrollWindow id pos t h v pd min init f as)
- = WindowAttributesHaveAttribute as StandByWindow;
- WindowDefIsStandBy (FixedWindow id pos t pd f as)
- = WindowAttributesHaveAttribute as StandByWindow;
-
- WindowAttributesHaveAttribute :: ![WindowAttribute s io] !(WindowAttribute s io) -> Bool;
- WindowAttributesHaveAttribute [Activate a : as] (Activate a` ) = True;
- WindowAttributesHaveAttribute [Deactivate d : as] (Deactivate d` ) = True;
- WindowAttributesHaveAttribute [GoAway g : as] (GoAway g` ) = True;
- WindowAttributesHaveAttribute [Keyboard ks kf : as] (Keyboard ks` kf`) = True;
- WindowAttributesHaveAttribute [Mouse ms mf : as] (Mouse ms` mf`) = True;
- WindowAttributesHaveAttribute [Cursor s : as] (Cursor s` ) = True;
- WindowAttributesHaveAttribute [StandByWindow : as] StandByWindow = True;
- WindowAttributesHaveAttribute [a : as] a` = WindowAttributesHaveAttribute as a`;
- WindowAttributesHaveAttribute as a = False;
-
- WindowDefGetActivate :: !(WindowDef s io) -> WindowFunction s io;
- WindowDefGetActivate (ScrollWindow id pos t h v pd min init f as)
- = GetWindowAttributeFunction as (Activate LazyWindowFunction);
- WindowDefGetActivate (FixedWindow id pos t pd f as)
- = GetWindowAttributeFunction as (Activate LazyWindowFunction);
-
- GetWindowAttributeFunction :: ![WindowAttribute s io] !(WindowAttribute s io)
- -> WindowFunction s io;
- GetWindowAttributeFunction [Activate a : as] (Activate a`) = a;
- GetWindowAttributeFunction [Deactivate d : as] (Deactivate d`) = d;
- GetWindowAttributeFunction [GoAway g : as] (GoAway g`) = g;
- GetWindowAttributeFunction [a : as] a` = GetWindowAttributeFunction as a`;
- GetWindowAttributeFunction as a = LazyWindowFunction;
-
- LazyWindowFunction :: *s *io -> (*s, *io);
- LazyWindowFunction s io = (s, io);
-
- WindowDefGetDeactivate :: !(WindowDef s io) -> WindowFunction s io;
- WindowDefGetDeactivate (ScrollWindow id pos t h v pd min init f as)
- = GetWindowAttributeFunction as (Deactivate LazyWindowFunction);
- WindowDefGetDeactivate (FixedWindow id pos t pd f as)
- = GetWindowAttributeFunction as (Deactivate LazyWindowFunction);
-
- WindowDefGetGoAway :: !(WindowDef s io) -> WindowFunction s io;
- WindowDefGetGoAway (ScrollWindow id pos t h v pd min init f as)
- = GetWindowAttributeFunction as (GoAway LazyWindowFunction);
- WindowDefGetGoAway (FixedWindow id pos t pd f as)
- = GetWindowAttributeFunction as (GoAway LazyWindowFunction);
-
- WindowDefGetCursor :: !(WindowDef s io) -> CursorShape;
- WindowDefGetCursor (ScrollWindow id pos t h v pd min init f as)
- = GetWindowAttributeCursor as;
- WindowDefGetCursor (FixedWindow id pos t pd f as)
- = GetWindowAttributeCursor as;
-
- GetWindowAttributeCursor :: ![WindowAttribute s io] -> CursorShape;
- GetWindowAttributeCursor [Cursor shape : as] = shape;
- GetWindowAttributeCursor [a : as] = GetWindowAttributeCursor as;
- GetWindowAttributeCursor as = StandardCursor;
-
- WindowDefGetKeyboard :: !(WindowDef s io) -> (!SelectState, !KeyboardFunction s io);
- WindowDefGetKeyboard (ScrollWindow id pos t h v pd min init f as)
- = GetWindowAttributeKeyboard as;
- WindowDefGetKeyboard (FixedWindow id pos t pd f as)
- = GetWindowAttributeKeyboard as;
-
- WindowDefGetMouse :: !(WindowDef s io) -> (!SelectState, !MouseFunction s io);
- WindowDefGetMouse (ScrollWindow id pos t h v pd min init f as)
- = GetWindowAttributeMouse as;
- WindowDefGetMouse (FixedWindow id pos t pd f as)
- = GetWindowAttributeMouse as;
-
- GetWindowAttributeKeyboard :: ![WindowAttribute s io] -> (!SelectState, !KeyboardFunction s io);
- GetWindowAttributeKeyboard [Keyboard ks kf : as] = (ks, kf);
- GetWindowAttributeKeyboard [a : as] = GetWindowAttributeKeyboard as;
- GetWindowAttributeKeyboard as = (Unable, LazyDeviceFunction);
-
- GetWindowAttributeMouse :: ![WindowAttribute s io] -> (!SelectState, !MouseFunction s io);
- GetWindowAttributeMouse [Mouse ms mf : as] = (ms, mf);
- GetWindowAttributeMouse [a : as] = GetWindowAttributeMouse as;
- GetWindowAttributeMouse as = (Unable, LazyDeviceFunction);
-
- // LazyDeviceFunction :: t * s * io -> (*s, *io);
- LazyDeviceFunction t s io = (s, io);
-
- ScrollBarDefGetValues :: !ScrollBarDef -> (!Int, !Int);
- ScrollBarDefGetValues (ScrollBar (Thumb t) (Scroll s)) = (t, s);
-
- WindowDefSetPictureDomain :: !PictureDomain !(WindowDef s io) -> WindowDef s io;
- WindowDefSetPictureDomain pd (ScrollWindow id pos t h v pd` min init f as)
- = ScrollWindow id pos t h v pd min init f as;
- WindowDefSetPictureDomain pd (FixedWindow id pos t pd` f as)
- = FixedWindow id pos t pd f as;
-
- WindowDefSetUpdate :: !(UpdateFunction s) !(WindowDef s io) -> WindowDef s io;
- WindowDefSetUpdate f (ScrollWindow id pos t h v pd min init f` as)
- = ScrollWindow id pos t h v pd min init f as;
- WindowDefSetUpdate f (FixedWindow id pos t pd f` as)
- = FixedWindow id pos t pd f as;
-
- WindowDefSetActivate :: !(WindowFunction s io) !(WindowDef s io) -> WindowDef s io;
- WindowDefSetActivate a (ScrollWindow id pos t h v pd min init f as)
- = ScrollWindow id pos t h v pd min init f (SetWindowAttributeFunction as (Activate a));
- WindowDefSetActivate a (FixedWindow id pos t pd f as)
- = FixedWindow id pos t pd f (SetWindowAttributeFunction as (Activate a));
-
- WindowDefSetDeactivate :: !(WindowFunction s io) !(WindowDef s io) -> WindowDef s io;
- WindowDefSetDeactivate da (ScrollWindow id pos t h v pd min init f as)
- = ScrollWindow id pos t h v pd min init f (SetWindowAttributeFunction as (Deactivate da));
- WindowDefSetDeactivate da (FixedWindow id pos t pd f as)
- = FixedWindow id pos t pd f (SetWindowAttributeFunction as (Deactivate da));
-
- WindowDefSetGoAway :: !(WindowFunction s io) !(WindowDef s io) -> WindowDef s io;
- WindowDefSetGoAway ga (ScrollWindow id pos t h v pd min init f as)
- = ScrollWindow id pos t h v pd min init f (SetWindowAttributeFunction as (GoAway ga));
- WindowDefSetGoAway ga (FixedWindow id pos t pd f as)
- = FixedWindow id pos t pd f (SetWindowAttributeFunction as (GoAway ga));
-
- SetWindowAttributeFunction :: ![WindowAttribute s io] !(WindowAttribute s io)
- -> [WindowAttribute s io];
- SetWindowAttributeFunction [Activate a : as] f=:(Activate a`) = [f : as];
- SetWindowAttributeFunction [Deactivate d : as] f=:(Deactivate d`) = [f : as];
- SetWindowAttributeFunction [GoAway g : as] f=:(GoAway g`) = [f : as];
- SetWindowAttributeFunction [a : as] a` = [a : SetWindowAttributeFunction as a`];
- SetWindowAttributeFunction as a` = [a`];
-
- WindowDefSetScrollBarDefs :: !(!(!Int,!Int), !(!Int,!Int)) !(WindowDef s io) -> WindowDef s io;
- WindowDefSetScrollBarDefs scrollBars (ScrollWindow id pos t h v pd min init f as)
- = ScrollWindow id pos t hBar vBar pd min init f as;
- where {
- hBar = ScrollBar (Thumb hThumb) (Scroll hScroll);
- vBar = ScrollBar (Thumb vThumb) (Scroll vScroll);
- (hThumb, hScroll) = hVals;
- (vThumb, vScroll) = vVals;
- (hVals, vVals) = scrollBars;
- };
- WindowDefSetScrollBarDefs scrollBars window = window;
-
- WindowDefSetMinimumSize :: !MinimumWindowSize !(WindowDef s io) -> WindowDef s io;
- WindowDefSetMinimumSize min (ScrollWindow id pos t h v pd min` init f as)
- = ScrollWindow id pos t h v pd min init f as;
- WindowDefSetMinimumSize min window = window;
-
- WindowDefSetCursor :: !CursorShape !(WindowDef s io) -> WindowDef s io;
- WindowDefSetCursor shape (ScrollWindow id pos t h v pd min init f as)
- = ScrollWindow id pos t h v pd min init f (SetWindowCursor as (Cursor shape));
- WindowDefSetCursor shape (FixedWindow id pos t pd f as)
- = FixedWindow id pos t pd f (SetWindowCursor as (Cursor shape));
-
- SetWindowCursor :: ![WindowAttribute s io] !(WindowAttribute s io) -> [WindowAttribute s io];
- SetWindowCursor [Cursor shape : as] cursor = [cursor : as];
- SetWindowCursor [a : as] cursor = [a : SetWindowCursor as cursor];
- SetWindowCursor as cursor = [cursor];
-
- WindowDefSetKeyboard :: !SelectState !(KeyboardFunction s io) !(WindowDef s io) -> WindowDef s io;
- WindowDefSetKeyboard ks kf (ScrollWindow id pos t h v pd min init f as)
- = ScrollWindow id pos t h v pd min init f (SetWindowAttributeDevice as (Keyboard ks kf));
- WindowDefSetKeyboard ks kf (FixedWindow id pos t pd f as)
- = FixedWindow id pos t pd f (SetWindowAttributeDevice as (Keyboard ks kf));
-
- WindowDefSetMouse :: !SelectState !(MouseFunction s io) !(WindowDef s io) -> WindowDef s io;
- WindowDefSetMouse ms mf (ScrollWindow id pos t h v pd min init f as)
- = ScrollWindow id pos t h v pd min init f (SetWindowAttributeDevice as (Mouse ms mf));
- WindowDefSetMouse ms mf (FixedWindow id pos t pd f as)
- = FixedWindow id pos t pd f (SetWindowAttributeDevice as (Mouse ms mf));
-
- SetWindowAttributeDevice :: ![WindowAttribute s io] !(WindowAttribute s io)
- -> [WindowAttribute s io];
- SetWindowAttributeDevice [Keyboard ks kf : as] (Keyboard ks` kf`) = [Keyboard ks` kf` : as];
- SetWindowAttributeDevice [Mouse ms mf : as] (Mouse ms` mf`) = [Mouse ms` mf` : as];
- SetWindowAttributeDevice [a : as] a` = [a : SetWindowAttributeDevice as a`];
- SetWindowAttributeDevice as a` = as;
-
- WindowDefGetFinalMinimumSize :: !(WindowDef s io) -> MinimumWindowSize;
- WindowDefGetFinalMinimumSize (ScrollWindow id pos t h v pd min init f as) = (48, 1);
- WindowDefGetFinalMinimumSize (FixedWindow id pos t pd f as) = (32, 1);
-